import UIKit

class MessageView: UIView {
    var isQuestion:Bool
    func bind(_ text:String){
        let paraph = NSMutableParagraphStyle()
        //将行间距设置为28
        paraph.lineSpacing = 6
        //样式属性集合
        let attributes = [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 15),
                          NSAttributedString.Key.paragraphStyle: paraph]
        textLabel.attributedText = NSAttributedString(string: text, attributes: attributes)
    }
    
    var textLabel: UILabel = {
        let titelLabel = UILabel()
        titelLabel.font = UIFont.systemFont(ofSize: 15)
        titelLabel.textAlignment = .left
        titelLabel.numberOfLines = 0
        
        return titelLabel
    }()
    
    init(isQuestion: Bool) {
        self.isQuestion = isQuestion
        super.init(frame: .zero)
        self.setupView()
    }
    
    required init?(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }
//    required init?(coder aDecoder: NSCoder) {
//        super.init(coder: aDecoder)
//        self.setupView()
//    }
    
    /// 初始化控件
    func setupView()  {
        self.addSubview(textLabel)
        self.layer.masksToBounds = true
        self.layer.cornerRadius = 18
        self.backgroundColor = .primaryColor
        if isQuestion{
            self.layer.maskedCorners = [.layerMinXMinYCorner, .layerMinXMaxYCorner, .layerMaxXMinYCorner]
        }else{
            self.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner, .layerMaxXMaxYCorner]
        }
        self.textLabel.snp.makeConstraints { (make) in
            make.left.top.equalTo(self).offset(12)
            make.bottom.right.equalTo(self).offset(-12)
            
        }
    }
    
}
